#ifndef CINPUT_H
#define CINPUT_H

#include <QWidget>
#include <QList>
#include <QHash>
#include <QQueue>
#include <QKeyEvent>

class CInput : public QObject
{
    Q_OBJECT

public:
    CInput( QWidget *parent );
    ~CInput();

    void KeyPressedEvent(QKeyEvent *e);
    void KeyReleaseEvent(QKeyEvent *e);
    void mousePressEvent(QMouseEvent* e);
    void mouseReleaseEvent(QMouseEvent *e);

    void windowDeactivateEvent();

    void handleInput();

    bool isKeyPressed( int key ) const;
    bool wasKeyPressed( int key ) const;
    bool wasKeyReleased( int key ) const;

    bool isButtonPressed( int key ) const;
    bool wasButtonPressed( int key ) const;
    bool wasButtonReleased( int key ) const;

    bool hasScreenLostFocus() const;

    QPoint getCursorPos() const;
    QPoint getCursorChange() const;
    bool hasMouseMoved() const;

    void setScaPos( double x, double  y, double sx, double sy );

private:
    QWidget *parent;

    // Keyboard
    QQueue<int> keyDownQueue, keyUpQueue;
    QList<int> keyDownList, keyUpList;
    QHash<int,bool> keyDownTable;

    // Mouse
    QQueue<int> buttonDownQueue, buttonUpQueue;
    QList<int> buttonDownList, buttonUpList;
    QHash<int,bool> buttonDownTable;

    int mx, my, // mouse position relation to window
        mdx, mdy; // mouse position change over last frame
    bool mouseMoved;
    bool windowDeactivatedSignal,
         windowDeactivated;
    double x, y, sx, sy;

};

#endif // CINPUT_H
